//
//  UserModel.m
//  HelpThePoor
//
//  Created by van7ish on 2016/12/5.
//  Copyright © 2016年 van7ish. All rights reserved.
//

#import "UserModel.h"

static UserModel *userModel = nil;

@implementation UserModel

+ (UserModel *)modelWithDictionary:(NSDictionary *)dictionary{
    return [[UserModel shareModel] initWithDictionary:dictionary];
}

- (id)initWithDictionary:(NSDictionary *)dictionary{
    if (self = [super init]) {
        [self setValue:dictionary[@"address"] forKey:@"address"];
        [self setValue:dictionary[@"birthDate"] forKey:@"birthDate"];
        [self setValue:dictionary[@"createTime"] forKey:@"createTime"];
        [self setValue:dictionary[@"id"] forKey:@"userId"];
        [self setValue:dictionary[@"lastLoginTime"] forKey:@"lastLoginTime"];
        [self setValue:dictionary[@"mobileNumber"] forKey:@"mobileNumber"];
        [self setValue:dictionary[@"organizationIcon"] forKey:@"organizationIcon"];
        [self setValue:dictionary[@"organizationId"] forKey:@"organizationId"];
        [self setValue:dictionary[@"organizationName"] forKey:@"organizationName"];
        [self setValue:dictionary[@"password"] forKey:@"password"];
        [self setValue:dictionary[@"remark"] forKey:@"remark"];
        [self setValue:dictionary[@"roleCode"] forKey:@"roleCode"];
        [self setValue:dictionary[@"sex"] forKey:@"sex"];
        [self setValue:dictionary[@"status"] forKey:@"status"];
        [self setValue:dictionary[@"userCode"] forKey:@"userCode"];
        [self setValue:dictionary[@"userName"] forKey:@"userName"];
        [self setValue:dictionary[@"idNumber"] forKey:@"idNumber"];
        [self setValue:dictionary[@"actualName"] forKey:@"actualName"];
    }
    return  self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}

//创建单例(唯一用户)
+ (UserModel *)shareModel
{
    //2、调用GCD（多线程的写法）的once方法来只做单例
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //大括号中的代码在整个应用中只会被执行一次
        //3、把上面的静态全局变量赋值，进行实例化
        userModel = [UserModel alloc];
    });
    //4、把静态全局指针变量返回
    return userModel;
}

@end
